<?php

namespace App\Transformers\User;

use App\Models\UserBill;
use League\Fractal\TransformerAbstract;

class UserBillsTransformer extends TransformerAbstract
{
    //可进行包含的信息
    protected $availableIncludes = [
        'user'
    ];

    public function transform(UserBill $userBill)
    {
        return [
            'id'=>$userBill->id,
            'user_id'=>$userBill->user_id ?? '',
            'link_id'=>$userBill->link_id ?? '',
            'pm'=>$userBill->pm ?? '',
            'title'=>$userBill->title ?? '',
            'category'=>$userBill->category ?? '',
            'type'=>$userBill->type ?? '',
            'Type_text'=>$userBill->typeEnum[$userBill->type] ?? '',
            'number'=>$userBill->number ?? '',
            'balance'=>$userBill->balance ?? '',
            'mark'=>$userBill->mark ?? '',
            'status'=>$userBill->status ?? '',
            'statusType'=>$userBill->statusEnum[$userBill->status] ?? '',
            'take'=>$userBill->take ?? 0,
            'created_at' => $userBill->created_at ? $userBill->created_at->format("Y-m-d H:i:s") : '',
            'delete_at' => $userBill->delete_at ? $userBill->delete_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $userBill->updated_at ? $userBill->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    public function includeUser(UserBill $userBill)
    {
        return $this->item($userBill->user, new UserTransformer());
    }
}
